#!/usr/bin/env python
# coding=utf-8
from flask import Blueprint

from plant.base.beanret import BeanRet
from plant.base.tools.config import Config
from plant.service.relaysv import RelaySV

pitop = Blueprint('pump', __name__)


@pitop.route('/pump/on')
def pumpOn():
    '''
    water plant api
    :return:
    '''
    gpio = int(Config().read("pump_pin", "pin"))
    relaySV = RelaySV(gpio)
    relaySV.on()
    return BeanRet(success=True).toJson()


@pitop.route('/pump/off')
def pumpOff():
    '''
    water plant api
    :return:
    '''

    relaySV = RelaySV(14)
    relaySV.off()
    return BeanRet(success=True).toJson()
